package com.schooleducation.service.impl;

import java.util.Date;
import java.util.List;

import com.schooleducation.entity.LessonComment;
import com.schooleducation.entity.LessonContent;
import com.schooleducation.entity.LessonReply;
import com.schooleducation.service.LessonCommentService;

public class LessonCommentServiceImpl extends SuperService implements LessonCommentService {

	@Override
	public List<LessonComment> getCommentList(int lessonContentId, int page) {
		// TODO Auto-generated method stub
		LessonComment lc = new LessonComment();
		LessonContent lContent = new LessonContent();
		lContent.setId(lessonContentId);
		lc.setLessonContent(lContent);
		
		return super.getDaoFac().getLessonCommentDao().getCommentListByLesson(lc, page, 20);
	}

	@Override
	public boolean addLessonComment(LessonComment lc) {
		// TODO Auto-generated method stub
		boolean flag = false;
		//数据合法验证
		if(lc.getCommentInfo().length() >= 6) {
			lc.setCommentDate(new Date());
			//储存留言信息
			super.getDaoFac().getLessonCommentDao().save(lc);
			flag = true;
		}
		
		return flag;
	}

	@Override
	public List<LessonComment> getCommentAndReplyList(int lessonContentId, int page) {
		// TODO Auto-generated method stub
		LessonComment lc = new LessonComment();
		LessonContent lContent = new LessonContent();
		lContent.setId(lessonContentId);
		lc.setLessonContent(lContent);
		
		return super.getDaoFac().getLessonCommentDao().getCommentAndReplyListByLesson(lc, page, 8);
	}

	@Override
	public boolean addLessonReply(LessonReply lr) {
		// TODO Auto-generated method stub
		boolean flag = false;
		//数据合法性验证
		if(lr.getContentInfo().length() >= 6) {
			//设定留言为未读
			lr.setIsRead(false);
			lr.setReplyDate(new Date());
			//储存回复信息
			super.getDaoFac().getLessonReplyDao().save(lr);
			flag = true;
		}
		
		return flag;
	}

	@Override
	public List<LessonReply> getLessonReplyListByComment(int commentId, int start) {
		// TODO Auto-generated method stub
		LessonReply lr = new LessonReply();
		LessonComment lc = new LessonComment();
		lc.setId(commentId);
		lr.setComment(lc);
		
		return super.getDaoFac().getLessonReplyDao().getReplyListByComment(lr, start, 10);
	}

	

}
